﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynCMS.NET.Core.Entities;

namespace DynCMS.NET.DataAccess.Mappings
{
    public class PageMap : Base.PersistableEntityMap<Page>
    {
        public static int UrlLength = 256;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:PageMap"/> class.
        /// </summary>
        public PageMap()
        {
            this.HasKey<string>(p => p.Url);

            this.HasRequired<Page>(p => p.Parent)
                .WithMany(p => p.Children)
                .HasForeignKey(p => p.ParentUrl);

            this.Property(p => p.Url)
                .HasColumnName("Url")
                .HasColumnType("nchar")
                .IsFixedLength()
                .HasMaxLength(UrlLength);

            this.Property(p => p.ParentUrl)
                .HasColumnName("ParentUrl")
                .IsUnicode()
                .HasColumnType("nchar")
                .IsFixedLength()
                .HasMaxLength(UrlLength);
        }
    }
}